package com.woniuxy.controller;

import com.woniuxy.conmon.MyPageData;
import com.woniuxy.pojo.Department;
import com.woniuxy.pojo.Disease;
import com.woniuxy.pojo.Result;
import com.woniuxy.pojo.dto.DiseaseDTO;
import com.woniuxy.service.DiseaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("disease")
@Api(tags = "疾病管理接口")
public class DiseaseController {
    @Autowired
    private DiseaseService diseaseService;

    @GetMapping("/getDisease/{pageNum}/{pageSize}")
    @ApiOperation(value = "获取疾病信息")
    public Result getDisease(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize){
       MyPageData disease = diseaseService.getDisease(pageNum, pageSize);
        return Result.ok(disease);
    }
    @DeleteMapping("/deleteDisease/{id}")
    @ApiOperation(value = "删除疾病信息")
    public Result deleteDisease(@PathVariable("id") Integer id){
        boolean b = diseaseService.removeById(id);
        return Result.ok(b);
    }
    @PostMapping("/batchDeleteDisease")
    @ApiOperation(value = "批量删除疾病信息")
    public Result batchDeleteDisease(@RequestBody List<Integer> ids){
        boolean b = diseaseService.removeByIds(ids);
        return Result.ok(b);
    }
    @GetMapping("/getDiseaseByDepartmentId")
    @ApiOperation(value = "获取科室下的疾病信息")
    public Result getDiseaseByDepartmentId( ){
        List<Department> departments = diseaseService.getDiseaseByDepartmentId( );
        return Result.ok(departments);
    }
    @GetMapping("/getDisease1/{id}")
    @ApiOperation(value = "根据疾病id获取单个疾病信息")
    public Result getDisease1(@PathVariable("id") Integer id){
        Disease disease = diseaseService.getDisease1(id);
        return Result.ok(disease);
    }
    // 新增疾病
    @PostMapping("/addDisease")
    @ApiOperation(value = "创建疾病")
    public Result createDisease(@RequestBody DiseaseDTO dto) {
        return diseaseService.createDisease(dto);
    }

    // 更新疾病
    @PostMapping("/updateDisease/{id}")
    @ApiOperation(value = "更新疾病")
    public Result updateDisease(
            @PathVariable Integer id,
            @RequestBody DiseaseDTO dto) {
        dto.setId(id);
        return diseaseService.updateDisease(dto);
    }
    @PostMapping("/searchDisease/{pageNum}/{pageSize}")
    @ApiOperation(value = "搜索疾病信息")
    public Result searchDisease(@PathVariable("pageNum") Integer pageNum,
                               @PathVariable("pageSize") Integer pageSize,
                              @RequestBody Disease disease){
        MyPageData disease1 = diseaseService.searchDisease(pageNum, pageSize, disease);
        return Result.ok(disease1);
    }

}
